package db_test;

import java.sql.*;

/**
 * Author: hu
 * Date: 2023/2/28 13:42
 */


public class SqlServerTest {

    // Connect to your database.
    // Replace server name, username, and password with your credentials
    public static void main(String[] args) {
        String connectionUrl =
                "jdbc:sqlserver://192.168.2.175:1433;"
                        +"DatabaseName=mydb;"
                        + "user=sa;"
                        + "password=HHdb@2023;";

        ResultSet resultSet = null;

        try (Connection connection = DriverManager.getConnection(connectionUrl);
             Statement statement = connection.createStatement()) {

            // Create and execute a SELECT SQL statement.
            String selectSql = "select top 1 * from dbo.t_abs;";
            resultSet = statement.executeQuery(selectSql);

            // Print results from select statement
            while (resultSet.next()) {
                System.out.println(resultSet.getInt(2) + " " + resultSet.getInt(3));
            }
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
    }
}